package com.annotation.conditional;

import com.annotation.entities.Person;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;

public class WhiteCondition implements Condition {

    @Override
    public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) {
        if (conditionContext.getEnvironment().getProperty("os.name").contains("Windows")){
            BeanDefinition beanDefinition = new RootBeanDefinition(Person.class);
            conditionContext.getRegistry().registerBeanDefinition("person2",beanDefinition);
            return true;
        }
        return false;
    }
}
